﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Navigation;
using HA.Data ;


namespace HA.ModFlow.Controls.DisplayOptions
{
    /// <summary>
    /// winSysbolAttributes.xaml 的交互逻辑
    /// </summary>
    public partial class winSysbolAttributes : Window
    {
        public winSysbolAttributes( Color colr,int size,DisplayShape dis)
        {
            InitializeComponent();
            this._clr2 = colr;            
            this.Size = size;
            this._displayshape = dis;
        }

        public winSysbolAttributes(Color colr,int size,DisplayShape dis, DOEntity entity)
        {
            InitializeComponent();

            this._clr2 = colr;
            this.Size = size;
            this._displayshape = dis;

            this.Entity = (DOEntity)entity.Clone();
            //this._clr2 = Color.FromArgb(this.Entity.Color.A, this.Entity.Color.R, this.Entity.Color.G, this.Entity.Color.B);
        }

        public void ConvertToRGBColor()
        {
            Color cl = this.Clr2;
            Entity.Color = System.Drawing.Color.FromArgb(cl.A, cl.R, cl.G, cl.B);
           
            Entity.Size = this.Size;
            Entity.DisplayShape = this.Displayshape;
           
        }
        DOEntity _entity=new DOEntity (new System.Drawing.Color(),DisplayShape.Circle );

        public DOEntity Entity
        {
            get { return _entity; }
            set { _entity = value; }
        }

        private DOModFlow modFlow=new DOModFlow ();

        //public object getStyle(int size, Color color, DisplayShape display)
        //{
        //    if (display == DisplayShape.Circle)
        //    {
        //        Ellipse ell = new Ellipse();
        //        ell.Fill = new SolidColorBrush(color);
        //        ell.Width = size;
        //        ell.Height = size;
        //        return ell;
        //    }
        //    if (display == DisplayShape.Square)
        //    {
        //        Rectangle rec=new Rectangle ();
        //        rec.Fill = new SolidColorBrush(color);
        //        rec.Width = size;
        //        rec.Height = size;
        //        return rec;                
        //    }
        //    if (display == DisplayShape.Diamond)
        //    {
        //        Rectangle rec = new Rectangle();
        //        rec.Fill = new SolidColorBrush(color);
        //        rec.Width = size;
        //        rec.Height = size;
        //        rec.RenderTransform = new RotateTransform(45, size / 2, size / 2);
        //        return rec;
        //    }

        //    if (display == DisplayShape.TriangleUp)
        //    {

        //        Polygon pol = new Polygon();
        //        pol.Fill = new SolidColorBrush(color);
        //        pol.Width = size;
        //        pol.Height = size;
        //        List<Point> arry = new List<Point>();
        //        arry.Add(new Point(size, 0));
        //        arry.Add(new Point(size / 2,size  ));
        //        arry.Add(new Point(0, 0));
        //        pol.Points = new PointCollection(arry );
        //        pol.RenderTransform = new RotateTransform(180, size / 2, size / 2);
        //        return pol;
        //    }

        //    if (display == DisplayShape.Cross)
        //    {
        //        Canvas canvas = new Canvas();
        //        canvas.Width = size;
        //        canvas.Height = size;
        //        Path path = new Path();
        //        GeometryConverter gc = new GeometryConverter();
        //         //"M0,0 L14,0"
        //        string str = "M0,0 L" + size + ",0";
               
        //        path.Data = (Geometry)gc.ConvertFromString(str );
        //        path.Margin = new Thickness(0, size /2, 0, 0);
        //        path.Stroke = new SolidColorBrush(color);
        //        path.StrokeThickness = 2;
        //        canvas.Children.Add(path);

        //        path = new Path();
        //        gc = new GeometryConverter();
        //        str = "M0,0 L0," + size ;
        //        path.Data = (Geometry)gc.ConvertFromString(str);
        //        path.Margin = new Thickness(size/2, 0, 0, 0);
        //        path.Stroke = new SolidColorBrush(color);
        //        path.StrokeThickness = 2;
        //        canvas.Children.Add(path);
        //        return canvas;
        //    }
        //    if (display == DisplayShape.CircleNoFill)
        //    {
        //        Ellipse ell = new Ellipse();
        //        ell.Stroke = new SolidColorBrush(color);
        //        ell.StrokeThickness = 2;
        //        ell.Width = size;
        //        ell.Height = size;
        //        return ell;
        //    }

        //    if (display == DisplayShape.SquareNoFill)
        //    {
        //        Rectangle rec = new Rectangle();               
        //        rec.Stroke = new SolidColorBrush(color);
        //        rec.StrokeThickness = 2;
        //        rec.Width = size;
        //        rec.Height = size;
        //        return rec;      
        //    }

        //    if (display == DisplayShape.DiamondNoFill)
        //    {
        //        Rectangle rec = new Rectangle();             
        //        rec.StrokeThickness = 2;
        //        rec.Stroke = new SolidColorBrush(color);
        //        rec.Width = size;
        //        rec.Height = size;
        //        rec.RenderTransform = new RotateTransform(45, size / 2, size / 2);
        //        return rec;
        //    }

        //    if (display == DisplayShape.TriangleNoFill)
        //    {
        //        Polygon pol = new Polygon();
        //        pol.Stroke  = new SolidColorBrush(color);
        //        pol.StrokeThickness=2;
        //        pol.Width = size;
        //        pol.Height = size;
        //        List<Point> arry = new List<Point>();
        //        arry.Add(new Point(size, 0));
        //        arry.Add(new Point(size / 2, size));
        //        arry.Add(new Point(0, 0));
        //        pol.Points = new PointCollection(arry);
        //        pol.RenderTransform = new RotateTransform(180, size / 2, size / 2);
        //        return pol;
        //    }
        //    if (display == DisplayShape.SlashCross)
        //    {
        //        Canvas canvas = new Canvas();
        //        canvas.Width = size;
        //        canvas.Height = size;
        //        Path path = new Path();
        //        GeometryConverter gc = new GeometryConverter();
        //        //"M0,0 L14,0"
        //        string str = "M"+size +",0"+" L0," + size;

        //        path.Data = (Geometry)gc.ConvertFromString(str);
        //        //path.Margin = new Thickness(0, size / 2, 0, 0);
        //        path.Stroke = new SolidColorBrush(color);
        //        path.StrokeThickness = 2;
        //        canvas.Children.Add(path);

        //        path = new Path();
        //        gc = new GeometryConverter();
        //        str = "M"+size*2+","+size +" L" + size+",0";
        //        path.Data = (Geometry)gc.ConvertFromString(str);
        //        path.Margin = new Thickness(-size , 0, 0, 0);

        //        path.Stroke = new SolidColorBrush(color);
        //        path.StrokeThickness = 2;
        //        canvas.Children.Add(path);
        //        return canvas;
        //    }
        //    return null;
        //}

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.btn.Content =this .modFlow .GetStyle (this .Size , _clr2, this ._displayshape);
            this.txtSize.Text = this.Size.ToString();

            SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(_clr2.A, _clr2.R, _clr2.G, _clr2.B));
            this.RectColor.Fill = solidColorBrush;
            switch (this._displayshape)
            {
                case DisplayShape.Circle :
                    this.rbtnCircle.IsChecked = true;
                    break;
                case DisplayShape.Square:
                    this.rbtnSquare.IsChecked = true;
                    break;
                case DisplayShape.Diamond:
                    this.rbtnDiamond.IsChecked = true;
                    break;
                case DisplayShape.TriangleUp:
                    this.rbtnTriangleUp.IsChecked = true;
                    break;
                //case DisplayShape.Cross:
                //    this.rbtnCross.IsChecked = true;
                //    break;
                //case DisplayShape.CircleNoFill:
                //    this.rbtnCircleNoFill.IsChecked = true;
                //    break;
                //case DisplayShape.SquareNoFill:
                //    this.rbtnSquareNoFill.IsChecked = true;
                //    break;
                //case DisplayShape.DiamondNoFill:
                //    this.rbtnDiamondNoFill.IsChecked = true;
                //    break;
                //case DisplayShape.TriangleNoFill:
                //    this.rbtnTriangleNoFill.IsChecked = true;
                //    break;
                //case DisplayShape.SlashCross:
                //    this.rbtnSlashCross.IsChecked = true;
                //    break;
            }
        }
        Color _clr2;

        public Color Clr2
        {
            get { return _clr2; }
            set { _clr2 = value; }
        }

        int _size = 8;

        public int Size
        {
            get { return _size; }
            set { _size = value; }
        }
        DisplayShape _displayshape = DisplayShape.Circle;

        public DisplayShape Displayshape
        {
            get { return _displayshape; }
            set { _displayshape = value; }
        }

        private void btnColor_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.ColorDialog dlg = new System.Windows.Forms.ColorDialog();
            Color color = new Color();
            color = this._clr2;
            dlg.Color = System.Drawing.Color.FromArgb(color.A, color.R, color.G, color.B);

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B));
                this.RectColor.Fill = solidColorBrush;

                _clr2 = Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B);
               try
               {
                   this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, this._displayshape);
                   
               }
               catch
               {
               }
            }

        }

        private void txtSize_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (Convert.ToInt32(this.txtSize.Text) >= 1 && Convert.ToInt32(this.txtSize.Text) <= 64)
                {
                    ShowGraph();
                    this.Size = Convert.ToInt32(this.txtSize.Text);
                }
                else
                {
                    this.txtSize.Text = "8";
                    ShowGraph();
                    this.Size =8;
                }
            }
            catch
            {
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void rbtnCircle_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void ShowGraph()
        {
            try
            {
                if (this.rbtnCircle.IsChecked.Value)
                {
                    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.Circle);
                    this._displayshape = DisplayShape.Circle;
                }
                if (this.rbtnSquare.IsChecked.Value)
                {
                    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.Square);
                    this._displayshape = DisplayShape.Square;
                }
                if (this.rbtnDiamond.IsChecked.Value)
                {
                    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.Diamond);
                    this._displayshape = DisplayShape.Diamond;
                }
                if (this.rbtnTriangleUp.IsChecked.Value)
                {
                    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.TriangleUp);
                    this._displayshape = DisplayShape.TriangleUp;
                }
                //if (this.rbtnCross.IsChecked.Value)
                //{
                //    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.Cross);
                //    this._displayshape = DisplayShape.Cross;
                //}
                //if (this.rbtnCircleNoFill.IsChecked.Value)
                //{
                //    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.CircleNoFill);
                //    this._displayshape = DisplayShape.CircleNoFill;
                //}
                //if (this.rbtnSquareNoFill.IsChecked.Value)
                //{
                //    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.SquareNoFill);
                //    this._displayshape = DisplayShape.SquareNoFill;
                //}
                //if (this.rbtnDiamondNoFill.IsChecked.Value)
                //{
                //    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.DiamondNoFill);
                //    this._displayshape = DisplayShape.DiamondNoFill;
                //}
                //if (this.rbtnTriangleNoFill.IsChecked.Value)
                //{
                //    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.TriangleNoFill);
                //    this._displayshape = DisplayShape.TriangleNoFill;
                //}
                //if (this.rbtnSlashCross.IsChecked.Value)
                //{
                //    this.btn.Content = this.modFlow.GetStyle(Convert.ToInt32(this.txtSize.Text), _clr2, DisplayShape.SlashCross);
                //    this._displayshape = DisplayShape.SlashCross;
                //}
            }
            catch { }
        }

        private void rbtnSquare_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnDiamond_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnTriangleUp_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnCross_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnCircleNoFill_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnSquareNoFill_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnDiamondNoFill_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnTriangleNoFill_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void rbtnSlashCross_Checked(object sender, RoutedEventArgs e)
        {
            ShowGraph();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {        
            this.DialogResult = true;
            this.Close();
            
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
      
    }
}

